﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using BookStore.Solution.BLL;
using BookStore.Solution.Utilities;

namespace BookStore.Solution.Presentation
{
    public enum SearchPosionType
    {
        ID,
        Name,
    }
    public partial class frmSearchPosition : DevComponents.DotNetBar.OfficeForm
    {
        bool IsSearchByID;
        public DataTable ResultTable { get; set; }
        private PositionManager manager;
        public frmSearchPosition(SearchPosionType type)
        {
            InitializeComponent();
            manager = new PositionManager();
            if (type == SearchPosionType.ID)
            {
                IsSearchByID = true;
                Text = "Tìm kiếm theo mã chức vụ";
            }
            else
            {
                IsSearchByID = false;
                Text = "Tìm kiếm theo tên chức vụ";
            }
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            txtKeyword.Border.BorderColor = StyleManager.ColorTint;
            if (txtKeyword.Text != "")
            {
                if (IsSearchByID)
                {
                    int id = DataUtil.ToInt(txtKeyword.Text);
                    ResultTable = manager.SearchByID(id);
                }
                else
                {
                    string name = txtKeyword.Text;
                    ResultTable = manager.SearchbyName(name);
                }
                if (ResultTable.Rows.Count > 0)
                    Close();
                else
                {
                    ResultTable = null;
                    MessageBox.Show("Không tìm thấy chức vụ nào phù hợp", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                ResultTable = null;
                MessageBox.Show("Từ khóa rỗng", "Thống báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtKeyword.Border.BorderColor = Color.Red;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            ResultTable = null;
        }
    }
}